package com.devin.service.Impl;

import com.devin.dao.MultiMapper;
import com.devin.dao.ProductMapper;
import com.devin.pojo.Product;
import com.devin.service.ProductService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("productService")
@Transactional
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductMapper productMapper;
    @Autowired
    private MultiMapper multiMapper;

    @Override
    public List<Product> findAllProducts(Integer page,Integer size) {
        PageHelper.startPage(page,size);
        List<Product> products = productMapper.findAllProducts();
        return products;
    }

    @Override
    public void addProduct(Product product) {
        productMapper.addProduct(product);
    }

    @Override
    public void delProduct(int id) {
        productMapper.delProduct(id);
    }

    @Override
    public List<Product> getAllProducts() {
        List<Product> products = productMapper.findAllProducts();
        return products;
    }

    @Override
    public void delProductsChecked(Integer[] ids) {
        multiMapper.delProductsChecked(ids);
    }

    @Override
    public Product getProductById(Integer productId) {
        return productMapper.getProductById(productId);
    }

    @Override
    public void updateProduct(Product product) {
        productMapper.updateProduct(product);
    }
}
